from core.basehandler import BaseHandler
from core.room import Room
#from items.nachos import Nacho
from core.support import set_cutscene
from core.action import Action
import random

class NachoContest(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.hav_won = False
        
        # add inventory items
        #self.add_item(Nacho())
        
        # build list of actions
        self.add_action(EatRNachos)
        self.add_action(EatPNachos)
        self.add_action(EatSNachos)
        self.add_action(Exits)
    
    # return description of room.
    def get_description(self):
        return "Welcome to NACHO MOUNTAIN!! Your arch-nemesis challenges you to a 'battle of the forces' nacho-eating competition. He explains the rules and its sounds a lot like paper-scissor-rock. Try to Tostito the competition. May the best Pendejo win!!"
    
    # return image of room
    def get_image(self):
        if self.hav_won == False:
            return 'nm.jpg'
        else:
            return 'nachocontest2.gif'


class NachoContestHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return NachoContest

# define actions for this room


class EatRNachos(Action):
    def __init__(self):
        Action.__init__(self, "eat_rock_nachos")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Eat rocky crunchy Nachos"
    # 1 = ROCK nachos
    # 2 = SCISSORS nachos
    # 3 = PAPER nachos
    
    def do_action(self,game,room,request):
        if room.get_id() == 'nacho_contest':
            if room.hav_won == False:
                set_cutscene("You decided to eat the rocky crunchy nachos")
                ai = random.randint(1, 3)
                player = 1
                if player == ai:
                    set_cutscene("Its a TIE !! Try again !!")
                    room.hav_won = False
                elif player == 1 and ai == 2:
                    set_cutscene("Your ROCKY nachos crushed his SCISSORY nachos")
                    room.hav_won = True
                else:
                    set_cutscene("Your ROCKY nachos got smothered by his PAPERY nachos")
                    room.hav_won = False
            else:
                set_cutscene("You have already won the contest goshdarnit !!")
                            
        else:
            set_cutscene("You cannot eat nachos here. Its business school after all.")
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
 
class EatPNachos(Action):
    def __init__(self):
        Action.__init__(self, "eat_paper_nachos")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Eat papery crispy Nachos"
    # 1 = ROCK nachos
    # 2 = SCISSORS nachos
    # 3 = PAPER nachos
    
    def do_action(self,game,room,request):
        if room.get_id() == 'nacho_contest':
            if room.hav_won == False:
                set_cutscene("You decided to eat the papery crispy nachos")
                ai = random.randint(1, 3)
                player = 3
                if player == ai:
                    set_cutscene("Its a TIE !! Try again !!")
                    room.hav_won = False
                elif player == 3 and ai == 2:
                    set_cutscene("Your PAPERY nachos got sliced by his RAZOR SHARP SCISSORY nachos")
                    room.hav_won = False
                else:
                    set_cutscene("Your PAPERY nachos smothered his ROCKY nachos")
                    room.hav_won = True
            else:
                set_cutscene("You have already won the contest goshdarnit !!")
                            
        else:
            set_cutscene("You cannot eat nachos here. Its business school after all.")
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
       
class EatSNachos(Action):
    def __init__(self):
        Action.__init__(self, "eat_scissor_nachos")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Eat scissory razor sharp Nachos"
    # 1 = ROCK nachos
    # 2 = SCISSORS nachos
    # 3 = PAPER nachos
    
    def do_action(self,game,room,request):
        if room.get_id() == 'nacho_contest':
            if room.hav_won == False:
                set_cutscene("You decided to eat the scissory razor sharp nachos")
                ai = random.randint(1, 3)
                player = 2
                if player == ai:
                    set_cutscene("Its a TIE !! Try again !!")
                    room.hav_won = False
                elif player == 2 and ai == 1:
                    set_cutscene("Your SCISSORY nachos got crushed by his ROCKY nachos")
                    room.hav_won = False
                else:
                    set_cutscene("Your SCISSORY nachos sliced his PAPERY nachos")
                    room.hav_won = True
            else:
                set_cutscene("You have already won the contest goshdarnit !!")
                            
        else:
            set_cutscene("You cannot eat nachos here. Its business school after all.")
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"

class Exits(Action):
    def __init__(self):
        Action.__init__(self, "Exit_Victory")    # do basic initialization for every action
    
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Exit & Emerge Victorious"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        if self.room.hav_won == True:
            return 'victory_room'
        else:
            return 'nacho_contest'
        
    def do_action(self,game,room,request):
        if self.room.hav_won == False:
            set_cutscene("You gotta win the contest to Emerge Victorious Pendejo !!")
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"